/*
package com.chinairi.mall.filter;

import com.chinairi.common.utils.RedisUtil;
import org.apache.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

*/
/**
 * AuthenticationTokenFilter
 * token过滤器，校验token有效性
 *
 * @author hmh
 * @date 2020.11.24
 *//*

@Component
public class AuthenticationTokenFilter extends OncePerRequestFilter {

    //token最小有效时间(毫秒) 5分钟
    private static final long MIN_EXPIRETIME = 60 * 1000 * 5;
    //token最小有效时间(分钟) 60分钟
    private static final long MAX_EXPIRETIME = 60 * 60;
    //登录请求
    private static final String LOGIN_PATH = "/sys-user-login/login";
    //注册请求
    private static final String REGISTERED_PATH = "/account/reg";

    private static final String VERIFICATIONCODE_PATH = "/verificationCode";

    private static final String CHECKEXITS_PATH = "/checkExist";
    //登陆页面
    private static final String LOGIN_PAGEPATH = "/account/login";

    private static final String LOGOUT_PATH = "/sys-user-login/logout";
    //游客请求
    private static final String VISITOR = "undefined";

    @Autowired
    RedisUtil redisUtill;

    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        */
/*String contextPath = httpServletRequest.getRequestURI();
        //放行登录请求或者注册请求
        if (contextPath.contains(LOGIN_PATH) || contextPath.contains(REGISTERED_PATH) || contextPath.contains(LOGOUT_PATH)
                || contextPath.contains(VERIFICATIONCODE_PATH) || contextPath.contains(CHECKEXITS_PATH)) {
            filterChain.doFilter(httpServletRequest, httpServletResponse);
            return;
        }*//*

        //获取token
        String token = httpServletRequest.getHeader("token");
        //携带token且token未过期或者是游客，游客token可能为空或者undefined
        if (StringUtils.isEmpty(token) || VISITOR.equals(token) || redisUtill.hasKey(token)) {
            if (redisUtill.hasKey(token)) {
                long expireTime = redisUtill.getExpire(token);
                //判断是否小于最小有效时间
                if (expireTime < MIN_EXPIRETIME) {
                    //重置有效时间
                    redisUtill.expire(token, MAX_EXPIRETIME);
                }
            }
            filterChain.doFilter(httpServletRequest, httpServletResponse);
            return;
        }
        redirectToLogin(httpServletRequest, httpServletResponse);
    }

    */
/**
     * 重定向到登录页
     *
     * @param request  req
     * @param response resp
     *//*

    @CrossOrigin(origins = "*", maxAge = 3600)
    private void redirectToLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //跨域
        response.setStatus(HttpStatus.SC_UNAUTHORIZED);
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
        //拼接url到登录页
//        ResponseUtil.showMessage(null, null, null);
    }
}
*/
